package com.lrkj.system.controller;

import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lrkj.common.annotation.Log;
import com.lrkj.common.core.controller.BaseController;
import com.lrkj.common.core.domain.AjaxResult;
import com.lrkj.common.enums.BusinessType;
import com.lrkj.system.domain.FiscalPeriod;
import com.lrkj.system.service.IFiscalPeriodService;
import com.lrkj.common.utils.poi.ExcelUtil;
import com.lrkj.common.core.page.TableDataInfo;

/**
 * 会计期间Controller
 *
 * @author yajun_ren
 * @date 2021-08-02
 */
@RestController
@RequestMapping("/system/fiscalPeriod")
public class FiscalPeriodController extends BaseController
{
    @Autowired
    private IFiscalPeriodService fiscalPeriodService;

    /**
     * 查询会计期间列表
     */
    @ApiOperation(value = "查询会计期间列表", notes = "查询会计期间列表")
    @PreAuthorize("@ss.hasPermi('system:fiscalPeriod:list')")
    @GetMapping("/list")
    public TableDataInfo list(FiscalPeriod fiscalPeriod)
    {
        startPage();
        List<FiscalPeriod> list = fiscalPeriodService.selectFiscalPeriodList(fiscalPeriod);
        return getDataTable(list);
    }

    /**
     * 导出会计期间列表
     */
	@ApiOperation(value = "导出会计期间列表", notes = "导出会计期间列表")
    @PreAuthorize("@ss.hasPermi('system:fiscalPeriod:export')")
    @Log(title = "会计期间", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FiscalPeriod fiscalPeriod)
    {
        List<FiscalPeriod> list = fiscalPeriodService.selectFiscalPeriodList(fiscalPeriod);
        ExcelUtil<FiscalPeriod> util = new ExcelUtil<FiscalPeriod>(FiscalPeriod.class);
        return util.exportExcel(list, "会计期间数据");
    }

    /**
     * 获取会计期间详细信息
     */
	@ApiOperation(value = "获取会计期间详细信息", notes = "获取会计期间详细信息")
    @PreAuthorize("@ss.hasPermi('system:fiscalPeriod:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(fiscalPeriodService.selectFiscalPeriodById(id));
    }

    /**
     * 新增会计期间
     */
	  @ApiOperation(value = "新增会计期间", notes = "新增会计期间")
    @PreAuthorize("@ss.hasPermi('system:fiscalPeriod:add')")
    @Log(title = "会计期间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FiscalPeriod fiscalPeriod)
    {
        return toAjax(fiscalPeriodService.insertFiscalPeriod(fiscalPeriod));
    }

    /**
     * 修改会计期间
     */
	 @ApiOperation(value = "修改会计期间", notes = "修改会计期间")
    @PreAuthorize("@ss.hasPermi('system:fiscalPeriod:edit')")
    @Log(title = "会计期间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FiscalPeriod fiscalPeriod)
    {
        return toAjax(fiscalPeriodService.updateFiscalPeriod(fiscalPeriod));
    }

    /**
     * 删除会计期间
     */
	 @ApiOperation(value = "删除会计期间", notes = "删除会计期间")
    @PreAuthorize("@ss.hasPermi('system:fiscalPeriod:remove')")
    @Log(title = "会计期间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(fiscalPeriodService.deleteFiscalPeriodByIds(ids));
    }
}
